using UnityEngine;

public class MessageMenu : MonoBehaviour
{
	public delegate void OnCompleteDelegate();

	public UITable table;

	public GameObject buttonPrefab;

	public GameObject window;

	private bool rebuild;

	public event OnCompleteDelegate onMessage;

	public event OnCompleteDelegate onResume;

	protected virtual void Start()
	{
		BuildMessageList();
		rebuild = false;
	}

	private void BuildMessageList()
	{
		int num = 0;
		bool[] array = new bool[PredefinedMessages.instance.messages.Count];
		if (GGPlayerSettings.instance.Model.multiplayerMessages != null)
		{
			foreach (string multiplayerMessage in GGPlayerSettings.instance.Model.multiplayerMessages)
			{
				GameObject gameObject = NGUITools.AddChild(table.gameObject, buttonPrefab);
				gameObject.SetActive(true);
				gameObject.name = num++.ToString();
				MessageButton component = gameObject.GetComponent<MessageButton>();
				component.Init(multiplayerMessage, true);
				for (int i = 0; i < PredefinedMessages.instance.messages.Count; i++)
				{
					if (multiplayerMessage == PredefinedMessages.instance.messages[i].message)
					{
						array[i] = true;
						break;
					}
				}
			}
		}
		for (int j = 0; j < PredefinedMessages.instance.messages.Count; j++)
		{
			if (!array[j])
			{
				GameObject gameObject2 = NGUITools.AddChild(table.gameObject, buttonPrefab);
				gameObject2.SetActive(true);
				gameObject2.name = num++.ToString();
				MessageButton component2 = gameObject2.GetComponent<MessageButton>();
				component2.Init(PredefinedMessages.instance.messages[j].message, false);
			}
		}
	}

	private void RebuildMessageList()
	{
	}

	public void MessageWasFavourited()
	{
		rebuild = true;
	}

	public virtual void OnClose()
	{
		if (this.onResume != null)
		{
			this.onResume();
		}
		window.SetActive(false);
	}

	public void OnOpen()
	{
		if (this.onMessage != null)
		{
			this.onMessage();
		}
		if (rebuild)
		{
			Debug.Log("Rebuilding Message List");
			RebuildMessageList();
			rebuild = false;
		}
		window.SetActive(true);
	}
}
